﻿using Microsoft.Owin.Security.Facebook;
using Owin;
using System.Configuration;
using System.Threading.Tasks;

namespace MoviesRoom
{
    public partial class Startup
    {
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Enable the application to use a cookie to store information for the signed in user
            // and to use a cookie to temporarily store information about a user logging in with a third party login provider
            app.UseSignInCookies();

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "",
            //    clientSecret: "");
            
            app.UseGoogleAuthentication();

            var fboptions = new FacebookAuthenticationOptions();
            fboptions.AppId = "566390653429738";
            fboptions.AppSecret = "6f4cafd7aa49947630e82edbaace6058";
            fboptions.SignInAsAuthenticationType = "External";
            fboptions.Provider = new FacebookAuthenticationProvider()
            {
                OnAuthenticated = (context) =>
                {
                    foreach (var v in context.User)
                    {
                        context.Identity.AddClaim(new System.Security.Claims.Claim(v.Key, v.Value.ToString()));
                    }
                    context.Identity.AddClaim(new System.Security.Claims.Claim("FacebookAccessToken", context.AccessToken));
                    return Task.FromResult(0);
                },
            };

            app.UseFacebookAuthentication(fboptions);
        }
    }
}